#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
转码模板Schema定义
"""

from pydantic import BaseModel, Field
from typing import Optional
from datetime import datetime

class TranscodeTemplateBase(BaseModel):
    name: str = Field(..., min_length=1, max_length=100, description="模板名称")
    description: Optional[str] = Field(None, max_length=500, description="模板描述")
    
    # 封装格式
    container_format: str = Field("mp4", description="封装格式: mp4, flv, ts, mkv")
    
    # 视频参数
    video_codec: str = Field("h264", description="视频编码: h264, h265")
    video_bitrate: int = Field(2000, ge=100, le=20000, description="视频码率(kbps)")
    video_resolution: str = Field("1920x1080", description="分辨率")
    video_fps: int = Field(25, ge=1, le=60, description="帧率")
    video_profile: Optional[str] = Field("high", description="编码档次")
    video_preset: Optional[str] = Field("medium", description="预设")
    
    # 音频参数
    audio_codec: str = Field("aac", description="音频编码: aac, mp3")
    audio_bitrate: int = Field(128, ge=32, le=512, description="音频码率(kbps)")
    audio_sample_rate: int = Field(44100, description="采样率")
    audio_channels: int = Field(2, ge=1, le=8, description="声道数")
    
    # 图片水印
    image_watermark_enabled: bool = Field(False, description="是否启用图片水印")
    image_watermark_path: Optional[str] = Field(None, description="水印图片路径")
    image_watermark_position: Optional[str] = Field("top-right", description="水印位置")
    image_watermark_opacity: int = Field(100, ge=0, le=100, description="水印透明度(0-100)")
    image_watermark_scale: float = Field(1.0, ge=0.1, le=5.0, description="水印缩放比例")
    
    # 文字水印
    text_watermark_enabled: bool = Field(False, description="是否启用文字水印")
    text_watermark_content: Optional[str] = Field(None, max_length=200, description="文字内容")
    text_watermark_position: Optional[str] = Field("bottom-right", description="文字位置")
    text_watermark_font: Optional[str] = Field("Arial", description="字体")
    text_watermark_size: int = Field(24, ge=8, le=100, description="字体大小")
    text_watermark_color: Optional[str] = Field("#FFFFFF", description="字体颜色")
    text_watermark_opacity: int = Field(100, ge=0, le=100, description="文字透明度(0-100)")
    
    # 高级选项
    custom_ffmpeg_args: Optional[str] = Field(None, description="自定义FFmpeg参数")
    
    # 状态
    is_default: bool = Field(False, description="是否为默认模板")
    is_active: bool = Field(True, description="是否启用")

class TranscodeTemplateCreate(TranscodeTemplateBase):
    pass

class TranscodeTemplateUpdate(BaseModel):
    name: Optional[str] = Field(None, min_length=1, max_length=100, description="模板名称")
    description: Optional[str] = Field(None, max_length=500, description="模板描述")
    container_format: Optional[str] = Field(None, description="封装格式")
    video_codec: Optional[str] = Field(None, description="视频编码")
    video_bitrate: Optional[int] = Field(None, ge=100, le=20000, description="视频码率")
    video_resolution: Optional[str] = Field(None, description="分辨率")
    video_fps: Optional[int] = Field(None, ge=1, le=60, description="帧率")
    video_profile: Optional[str] = Field(None, description="编码档次")
    video_preset: Optional[str] = Field(None, description="预设")
    audio_codec: Optional[str] = Field(None, description="音频编码")
    audio_bitrate: Optional[int] = Field(None, ge=32, le=512, description="音频码率")
    audio_sample_rate: Optional[int] = Field(None, description="采样率")
    audio_channels: Optional[int] = Field(None, ge=1, le=8, description="声道数")
    image_watermark_enabled: Optional[bool] = Field(None, description="是否启用图片水印")
    image_watermark_path: Optional[str] = Field(None, description="水印图片路径")
    image_watermark_position: Optional[str] = Field(None, description="水印位置")
    image_watermark_opacity: Optional[int] = Field(None, ge=0, le=100, description="水印透明度")
    image_watermark_scale: Optional[float] = Field(None, ge=0.1, le=5.0, description="水印缩放比例")
    text_watermark_enabled: Optional[bool] = Field(None, description="是否启用文字水印")
    text_watermark_content: Optional[str] = Field(None, max_length=200, description="文字内容")
    text_watermark_position: Optional[str] = Field(None, description="文字位置")
    text_watermark_font: Optional[str] = Field(None, description="字体")
    text_watermark_size: Optional[int] = Field(None, ge=8, le=100, description="字体大小")
    text_watermark_color: Optional[str] = Field(None, description="字体颜色")
    text_watermark_opacity: Optional[int] = Field(None, ge=0, le=100, description="文字透明度")
    custom_ffmpeg_args: Optional[str] = Field(None, description="自定义FFmpeg参数")
    is_default: Optional[bool] = Field(None, description="是否为默认模板")
    is_active: Optional[bool] = Field(None, description="是否启用")

class TranscodeTemplateResponse(TranscodeTemplateBase):
    id: int
    created_at: datetime
    updated_at: Optional[datetime]
    
    class Config:
        from_attributes = True

class TranscodeTemplateList(BaseModel):
    items: list[TranscodeTemplateResponse]
    total: int
    page: int
    size: int